declare @InventoryCategoryID uniqueidentifier
declare @ParentID uniqueidentifier
declare @InventoryCategoryCode nvarchar(20)
	
DECLARE Cursor_ItemCats CURSOR FOR
			select InventoryCategoryID, ParentID, InventoryCategoryCode
			from dbo.InventoryItemCategory
			where (IsParent = 0 or IsParent is null)
			and parentid is not null
			and InventoryCategoryCode not like '%-%'
			
OPEN Cursor_ItemCats;
	FETCH NEXT FROM Cursor_ItemCats
	INTO @InventoryCategoryID, @ParentID, @InventoryCategoryCode;
	
	WHILE @@FETCH_STATUS = 0
		BEGIN
			declare @ParentInventoryCategoryCode nvarchar(20)
			
			select @ParentInventoryCategoryCode = InventoryCategoryCode 
			from dbo.InventoryItemCategory
			where InventoryCategoryID = @ParentID
			
			UPDATE dbo.InventoryItemCategory set 
			InventoryCategoryCode = @ParentInventoryCategoryCode + '-' + @InventoryCategoryCode
			WHERE CURRENT OF Cursor_ItemCats;
			
			FETCH NEXT FROM Cursor_ItemCats
			INTO @InventoryCategoryID, @ParentID, @InventoryCategoryCode;
		END;
	CLOSE Cursor_ItemCats;
	DEALLOCATE Cursor_ItemCats;